#encoding: utf-8
class LibraryBorrowRecord < ActiveRecord::Base
  attr_accessible :borrowed_on, :description, :due_date, :id, :library_document_id, :student_id, :returned_on, :status
  #before_update :up_quantity_count
  #before_save :up_count
  #after_find :check_document_exist
  #
  #private
  #def check_document_exist
  #  #check document exist or deleted?
  #  LibraryDocument.find_by_id(self.library_document_id)
  #end
  belongs_to :library_document
  belongs_to :student

  def up_quantity_count
    LibraryDocument.increment_counter('quantity',self.library_document_id)
  end

  def up_count
      LibraryDocument.increment_counter('lend_count',self.library_document_id)
      LibraryDocument.decrement_counter('quantity',self.library_document_id)
  end
end
